home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14062 < prev    next >
Encoding:
Text File  |  1996-08-05  |  880 b   |  37 lines

  1. Path: spiff.cc.iastate.edu!graphix
  2. From: graphix@iastate.edu (Kent A Vander Velden)
  3. Newsgroups: comp.lang.c++
  4. Subject: Derivation and calling virtual functions
  5. Date: 28 Mar 96 17:04:49 GMT
  6. Organization: Iowa State University, Ames, Iowa
  7. Message-ID: <graphix.828032689@spiff.cc.iastate.edu>
  8. NNTP-Posting-Host: spiff.cc.iastate.edu
  9.  
  10.   Say we have the following:
  11.  
  12. class Base {
  13. public:
  14.   virtual void func() { // some stuff }
  15.   virtual void write() { func(); };
  16. };
  17.  
  18. class Derived : public Base {
  19. public:
  20.   void func() { // some stuff }
  21.   write(); { Base::func(); }
  22. };
  23.  
  24. Derived inst;
  25.  
  26.   Now, when I call inst.write() it in turn calls Bass::write() which in
  27. turn calls Base::func().  Is there a way to instead have it call
  28. Derived::func() if the instance is of type Derived?  I hoped the 
  29. virtual keyword would help in this case.
  30.  
  31.   Thanks.
  32.  
  33. -- 
  34. Kent Vander Velden
  35. graphix@iastate.edu
  36.  
  37.